#include <QtGui/QApplication>
#include <QMessageBox>
#include <QLibrary>
#include <engine.h>
#include "spacewargame.h"

#pragma comment(lib, "..\\..\\bin\\engine.lib")

int main(int argc, char *argv[])
{
	QLibrary engine("Engine");
	if(!engine.load())
	{
		 int ret = QMessageBox::critical(NULL, 
								QObject::tr("My Application"),
                                QObject::tr("Tank Game must be need Engine.dll"),
                                QMessageBox::Ok);

		return 0;
	}


	QApplication a(argc, argv);

	SpaceWarGame* pGame = new SpaceWarGame;
    if(!pGame)
        return 0;

	//Engine Initialize
	typedef bool (*fn)(GGame* p); 
	fn eng_init = (fn)engine.resolve("engine_initialize");
	if(!eng_init(pGame))
	{
		int ret = QMessageBox::critical(NULL, 
								QObject::tr("My Application"),
                                QObject::tr("Tank Game is not initialized"),
                                QMessageBox::Ok);
		return 0;
	}

    GEngine::GetEngine()->EngineStart();
	pGame->mainWindow()->show();
	int ret = a.exec();
	GEngine::GetEngine()->EngineEnd();

	delete pGame;

	return ret;
}


//int main(int argc, char *argv[])
//{
//	QApplication a(argc, argv);
//	
//	SpaceWarGame* pGame = new SpaceWarGame;
//
//	GEngine* pEngine = new GEngine;
//    if (pEngine == NULL || !GEngine::GetEngine()->EngineInitialize(pGame))
//		return 0;
//    
//    GEngine::GetEngine()->EngineStart();
//	
//	pGame->mainWindow()->show();
//    int ret = a.exec();
//
//    GEngine::GetEngine()->EngineEnd();
//    
//	return ret;	
//}
